package com.domor.system.domain;

import com.domor.common.core.domain.BaseEntity;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;

import javax.validation.constraints.Email;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.Size;
import java.util.Date;
import java.util.List;

/**
 * 用户对象 sys_user
 *
 * @author domor
 */
@Data
@ApiModel("用户信息")
@EqualsAndHashCode(callSuper = true)
public class SysUser extends BaseEntity {

    private static final long serialVersionUID = 1L;

    @ApiModelProperty("用户ID")
    private Long userId;

    @ApiModelProperty("部门ID")
    private Long deptId;

    @ApiModelProperty("部门父ID")
    private Long parentId;

    @ApiModelProperty("登录名称")
    @NotBlank(message = "登录账号不能为空")
    @Size(min = 0, max = 30, message = "登录账号长度不能超过30个字符")
    private String loginName;

    @ApiModelProperty("用户名称")
    @Size(min = 0, max = 30, message = "用户昵称长度不能超过30个字符")
    private String userName;

    @ApiModelProperty("用户类型")
    private String userType;

    @ApiModelProperty("用户邮箱")
    @Email(message = "邮箱格式不正确")
    @Size(min = 0, max = 50, message = "邮箱长度不能超过50个字符")
    private String email;

    @ApiModelProperty("手机号码")
    @Size(min = 0, max = 11, message = "手机号码长度不能超过11个字符")
    private String phone;

    @ApiModelProperty("用户性别")
    private String sex;

    @ApiModelProperty("用户头像")
    private String avatar;

    @ApiModelProperty("密码")
    private String password;

    @ApiModelProperty("盐加密")
    private String salt;

    @ApiModelProperty("帐号状态（0正常 1停用）")
    private Integer status;

    @ApiModelProperty("最后登陆IP")
    private String loginIp;

    @ApiModelProperty("最后登陆时间")
    private Date loginDate;

    @ApiModelProperty("部门对象")
    private SysDept dept;

    @ApiModelProperty("部门名称")
    private String deptName;

    @ApiModelProperty("用户角色列表")
    private List<SysRole> roles;

    @ApiModelProperty("用户角色名称")
    private String roleName;

    public SysUser() {
    }

    public SysUser(Long userId) {
        this.userId = userId;
    }

    public boolean isAdmin() {
        return isAdmin(this.userId);
    }

    public static boolean isAdmin(Long userId) {
        return userId != null && 1L == userId;
    }

}
